<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目列表')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>搜索内容：</label>
                                <input type="text" name="title" placeholder="名称/简称/编号/描述" />
                            </li>
                            <li>
                                <label>开工时间：</label>
                                <input type="text" class="time-input" style="width: 80px;" placeholder="开始时间" name="params[beginTime]"/>
                                <sapn> - </sapn>
                                <input type="text" class="time-input" style="width: 80px;" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <label>项目类型：</label>
                                <select name="projectType" class="form-control m-b" th:with="type=${@dict.getType('project_type')}">
                                    <option value="">--请选择--</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue == 'develop'}"></option>
                                </select>
                            </li>
                            <li>
                                <label>项目阶段：</label>
                                <select name="projectStage" style="width: 100px;" class="form-control m-b" th:with="type=${@dict.getType('project_stage')}">
                                    <option value="">--请选择--</option>
                                    <option value="unClose" selected="selected">未结束</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>项目经理：</label>
                                <select name="projectManager" style="width: 100px;" class="form-control m-b" th:with="type=${@customDictService.selectUserList()}">
                                    <option value="">--请选择--</option>
                                    <option th:each="dict : ${type}" th:text="${dict.userName}" th:value="${dict.userId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>事业部：</label>
                                <select name="businessUnitId" id="businessUnitId" style="width: 100px;" class="form-control m-b" th:with="type=${@customDictService.selectDictBusinessUnit()}">
                                    <option value="">--请选择--</option>
                                    <option th:each="dict : ${type}" th:text="${dict.name}" th:value="${dict.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>商务经理：</label>
                                <select name="accountManager" style="width: 100px;" class="form-control m-b" th:with="type=${@customDictService.selectUserList()}">
                                    <option value="">--请选择--</option>
                                    <option th:each="dict : ${type}" th:text="${dict.userName}" th:value="${dict.userId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>交付经理：</label>
                                <select name="deliveryManager" style="width: 100px;" class="form-control m-b" th:with="type=${@customDictService.selectUserList()}">
                                    <option value="">--请选择--</option>
                                    <option th:each="dict : ${type}" th:text="${dict.userName}" th:value="${dict.userId}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="erp:project:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="erp:project:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
     <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('erp:project:edit')}]];
        var removeFlag = [[${@permission.hasPermi('erp:project:remove')}]];
        var staffingSettingFlag = [[${@permission.hasPermi('staffing:setting:edit')}]];
        var memberViewFlag = [[${@permission.hasPermi('erp:project:member:view')}]];
        var bonusViewFlag = [[${@permission.hasPermi('erp:projectBonus:user:view')}]];
        var prefix = ctx + "erp/project";
        var projectTypeData = [[${@dict.getType('project_type')}]];
        var projectStageDatas = [[${@dict.getType('project_stage')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: 'id',
                sortOrder: "desc",
                modalName: "项目",
                columns: [
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'projectCode',
                    title: '项目编号'
                },
                {
                    field: 'title',
                    title: '项目名称'
                },
                {
                    field: 'projectType',
                    title: '项目类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(projectTypeData, value);
                    }
                },
                {
                    field: 'projectStage',
                    title: '项目阶段',
                    formatter(value, row)
                    {
                        return $.table.selectDictLabel(projectStageDatas, value);
                    }
                },
                {
                    field: 'businessUnitName',
                    title: '事业部'
                },
                {
                    field: 'customerName',
                    title: '客户简称'
                },
                {
                    field: 'kickoffDate',
                    title: '开工时间',
                    sortable: true,
                },
                // {
                //     field: 'tax',
                //     title: '税率(%)'
                // },
                {
                    field: 'amount',
                    title: '合同/PO金额'
                },
                // {
                //     field: 'billedAmount',
                //     title: '结算金额'
                // },
                // {
                //     field: 'payedAmount',
                //     title: '已收金额'
                // },
                {
                    field: 'projectManagerName',
                    title: '项目经理'
                },
                {
                    field: 'accountManagerName',
                    title: '商务经理'
                },
                {
                    field: 'deliveryManagerName',
                    title: '交付经理'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        var settingUrl =  "/staffing/setting/modal/project/" + row.id;
                        var memberUrl = "/erp/project/" + row.id + "/member";
                        var bonusUrl = "/erp/projectBonusUser/project/" + row.id;
                        if (row.projectType == "staffing"){
                            actions.push('<a class="btn btn-success btn-xs ' + staffingSettingFlag + '" href="javascript:void(0)" onclick="$.modal.open(\'项目 ' + row.shortTitle + ' 外派属性设置\',\''+ settingUrl+ '\',\'700\',\'700\')"><i class="fa fa-cogs"></i>&nbsp;外派属性</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + memberViewFlag + '" href="javascript:void(0)" onclick="$.modal.openTab(\'' + row.title + '--成员\',\'' + memberUrl + '\')"><i class="fa fa-group"></i>&nbsp;成员</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + bonusViewFlag + '" href="javascript:void(0)" onclick="$.modal.openTab(\'' + row.title + '--提成人员\',\'' + bonusUrl + '\')"><i class="fa fa-dollar"></i>&nbsp;提成</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

    </script>
</body>
</html>